package com.ssm.blog.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.blog.pojo.Diary;
import com.ssm.blog.pojo.Mood;
import com.ssm.blog.pojo.criteria.DiaryCriteria;
import com.ssm.blog.pojo.criteria.MoodCriteria;
import com.ssm.blog.service.DiaryService;
import com.ssm.blog.service.MoodService;
import com.ssm.blog.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/mood.html")
public class MoodController {
    @Autowired
    private MoodService moodService;

    @RequestMapping(params = "act=list")
    @ResponseBody
    public Map<String, Object> roleTable(MoodCriteria criteria, Integer page, int rows) {
        PageInfo<Mood> pageInfo = moodService.getMoodList(criteria, page, rows);
        //key不可以改，页面上分页插件需要
        return JsonUtil.getDatagridPagerResult(pageInfo.getTotal(), pageInfo.getList());
    }

    @RequestMapping(params = "act=add")
    @ResponseBody
    public Map<String, Object> add(Mood mood) {
        mood.setUserId(1);
        moodService.addMood(mood);
        return JsonUtil.getSuccessMessage("添加成功", null);
    }

    @RequestMapping(params = "act=delete")
    @ResponseBody
    public Map<String, Object> delete(Integer id) {
        moodService.deleteMood(id);
        return JsonUtil.getSuccessMessage("删除成功", null);
    }
}
